package com.mygdx.game.Screens;

import com.badlogic.gdx.*;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.mygdx.game.B2WorldCreator;
import com.mygdx.game.MyGdxGame;
import com.mygdx.game.Scenes.Hud;
import com.mygdx.game.Sprite.Mario;
import com.mygdx.game.Sprite.NPC;
import com.mygdx.game.Stage.GeneralStage;
import com.mygdx.game.Stage.IndexStage;


public class BeginScreen implements Screen {
    public static MyGdxGame game;

    //Box2d
    private float timer;
    // 纹理画布
    private SpriteBatch batch;
    public static Music music;
    // 纹理
    private Texture texture;
    private Texture master;
    private Sprite spriteMaster;
    public BeginScreen(final MyGdxGame game) {
        this.game = game;
        music = Gdx.audio.newMusic(Gdx.files.internal("music/GG.mp3"));  // music
        // 背景音乐设置循环播放
        music.setLooping(true);
        music.setVolume((float) 0.8);
        music.play();


        batch = new SpriteBatch();
        texture = new Texture("start/background.jpg");
        //添加怪兽
        master = new Texture("start/Morgen.png");
        // 使用纹理创建精灵, 精灵宽高为该纹理的宽高
        spriteMaster = new Sprite(master);
        // 设置精灵的位置（左下角绘制起点）   实验:大型怪兽从中心出现
        spriteMaster.setPosition(0, 0);
        spriteMaster.setSize(800, 800);
        // 设置日志输出级别
        Gdx.app.setLogLevel(Application.LOG_DEBUG);


    }

    @Override
    public void show() {

    }
    @Override
    public void render(float delta) {

        Gdx.gl.glClearColor(0, 0, 0, 0);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        carton();
    }
    public void carton() {
        timer = timer += Gdx.graphics.getDeltaTime();

        /* 使用画笔将纹理绘制在屏幕上 */
        batch.begin();                // 绘制开始
        batch.draw(texture, 0, 0);	// 在屏幕左下角绘制纹理
        // 1.移动
        if (timer < 3) {
            spriteMaster.translateX(1200 * Gdx.graphics.getDeltaTime());
            spriteMaster.rotate(1200 * Gdx.graphics.getDeltaTime());
        }
        // 2.翻转/放缩
        else if (timer > 3 && timer < 5) {
            //每秒旋转90度
            spriteMaster.setPosition(780, 240);
            // spriteMaster.setScale(1, 1);
            spriteMaster.rotate(90 * Gdx.graphics.getDeltaTime() * 10);
            spriteMaster.scale(1 * Gdx.graphics.getDeltaTime());

        } else {
            //舞台跳转
            spriteMaster.setPosition(1350, 170);
            spriteMaster.setSize(500, 500);
            spriteMaster.setScale(1, 1);
            spriteMaster.setRotation(0);
            game.setScreen(new PlayScreen(game));
        }
        spriteMaster.draw(batch);
        batch.end();

        // 绘制结束
    }
    @Override
    public void resize(int width, int height) {

    }
    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {

    }
}
